//
//  ViewController.m
//  AFNScrollViewInMasonryBeta
//
//  Created by king on 15/12/1.
//  Copyright © 2015年 king. All rights reserved.
//

#import "ViewController.h"
#import "TestModel.h"
#import "Masonry.h"
#import "ScrollViewMasonry.h"
#import "AFNetworking.h"

@interface ViewController ()

@property(nonatomic, strong) ScrollViewMasonry *scrollView;
@property(nonatomic, strong) NSMutableArray *resultArr;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.title = @"ScrollView利用Masonry适配Beta1";
    self.view.backgroundColor = [UIColor yellowColor];
//    self.scrollView.arr = [NSArray]
    [self requestData];
}
#pragma mark - Method 懒加载
- (ScrollViewMasonry *)scrollView {
    if (!_scrollView) {
        _scrollView = [[ScrollViewMasonry alloc] initWithImageTimeInterval:1];
        [self.view addSubview:_scrollView];
        [_scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.view).with.insets
            (UIEdgeInsetsMake(0,0,0,0));
        }];
//        [_scrollView setAutoScroll:NO];
    }
    return _scrollView;
}
#pragma mark - Method 网络请求数据
- (void)requestData {
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    [manager.responseSerializer setAcceptableContentTypes:[NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html",@"text/css",@"text/plain",@"application/javascript", nil]];
    [manager GET:@"http://app.api.autohome.com.cn/autov5.0.0/news/newslist-pm1-c0-nt0-p1-s30-l0.json" parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = responseObject;
        self.resultArr = [TestModel baseModelByArr:dic[@"result"][@"focusimg"]];
        self.scrollView.arr = self.resultArr;
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
